package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.common.lib.constant.EventBusEvent;
import com.common.lib.fragment.BaseFragment;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.thinkfit.jy.R;
import com.thinkfit.jy.activity.SettingNewOtherActivity;
import com.thinkfit.jy.activity.SwitchScreenProtectActivity;
import com.thinkfit.jy.utils.DeviceTypeUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

/**
 * 设置屏保样式和时间
 */
public class ScreenProtectFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {
    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
//        return DataManager.Companion.getInstance().getMainStyle() == 3 ? R.layout.fragment_screen_protect_xm :
        return   R.layout.fragment_screen_protect;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        setViewsOnClickListener(R.id.tvBack, R.id.llTime, R.id.llStyle);
    }

    public void onResume() {
        super.onResume();
        setText(R.id.tvTime, getString(
                getResources().getIdentifier("app_time_" + DataManager.Companion.getInstance().getScreenTime(),
                        "string", getActivity().getPackageName())
        ));
        setText(R.id.tvStyle, getString(
                getResources().getIdentifier("app_screen_protect_style_" + DataManager.Companion.getInstance().getScreenProtectStyle(),
                        "string", getActivity().getPackageName())
        ));
    }
    @Override
    public void onStop() {
        super.onStop();
        System.out.println("ddddddddddddddddddddddd   ScreenProtectFragment ");
        DeviceTypeUtils.showBackButton(getContext().getApplicationContext());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvBack:
                getParentFragmentManager().popBackStack();
                break;
            case R.id.llTime:
//                ((SettingActivity) getActivity()).toFragment(new SelectScreenProtectTimeFragment());
//                Bundle bundle = new Bundle();
//                bundle.putInt(Constants.BUNDLE_EXTRA, SettingNewOtherActivity.SCREEN_SAVER_TIME);
//                openActivity(SettingNewOtherActivity.class,bundle);
                HashMap<String, Object> map = new HashMap<>();
                map.put(EventBusEvent.REFRESH_ACTIVITY, SettingNewOtherActivity.SCREEN_SAVER_TIME);
                EventBus.getDefault().post(map);
                break;
            case R.id.llStyle:
                openActivity(SwitchScreenProtectActivity.class);
                break;
        }
    }
}
